package com.github.wxiaoqi.security.checkout.rest;

import com.github.wxiaoqi.security.checkout.common.utils.util.PageList;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.github.wxiaoqi.security.checkout.model.CompanyLoginModel;
import com.github.wxiaoqi.security.checkout.service.CompanyLoginService;
import java.util.HashMap;
import java.util.Map;

/**
* 类名: CompanyLoginController
* @author wjt
*/
@RestController
@RequestMapping("companyLogin")
public class CompanyLoginController {
    private final static Logger logger = LoggerFactory.getLogger(CompanyLoginController.class);

    @Autowired
    private CompanyLoginService companyLoginService;

    @ApiOperation("保存")
    @RequestMapping(value = "save",method = RequestMethod.POST)
    @ResponseBody
    public ObjectRestResponse<Object> save(@RequestBody CompanyLoginModel companyLoginModel){
        logger.info("CompanyLoginController.save()");
        companyLoginService.save(companyLoginModel);
        return new ObjectRestResponse<Object>().rel(true);
    }

    @ApiOperation("根据ID获取记录信息")
    @RequestMapping(value = "findById",method = RequestMethod.GET)
    @ResponseBody
    public ObjectRestResponse<CompanyLoginModel> findById(@RequestParam(value = "companyLoginId") Long companyLoginId){
        logger.info("CompanyLoginController.findById()");
        CompanyLoginModel model = companyLoginService.findById(companyLoginId);
        return new ObjectRestResponse<CompanyLoginModel>().rel(true).data(model);
    }

    @ApiOperation("分页查询")
    @RequestMapping(value = "findPageList",method = RequestMethod.GET)
    @ResponseBody
    public ObjectRestResponse<Object> findPageList(CompanyLoginModel companyLoginModel, @RequestParam(value = "pageIndex", required = false) Integer pageIndex, @RequestParam(value = "pageSize", required = false) Integer pageSize){
        logger.info("CompanyLoginController.findPageList()");
        if (pageIndex == null) pageIndex = 0;
        if (pageSize == null) pageSize = 10;
        PageList<CompanyLoginModel> pageList = companyLoginService.pageListByParams(companyLoginModel, pageIndex, pageSize);
        Map<String, Object> resultData = new HashMap<>();
        resultData.put("listData", pageList);
        resultData.put("paginator", pageList.getPaginator());
        return new ObjectRestResponse<Object>().rel(true).data(resultData);
    }

    @ApiOperation("删除")
    @RequestMapping(value = "del/{companyLoginId}",method = RequestMethod.POST)
    @ResponseBody
    public ObjectRestResponse<Object> del(@PathVariable Long companyLoginId){
        logger.info("CompanyLoginController.del()");
        int i = companyLoginService.delete(companyLoginId);
        return new ObjectRestResponse<Object>().rel(true).data(i);
    }

}
